package com.xiaolin.spring.xml;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @ClassName PropertyTest
 * @Description TODO
 * @Detail 构造器注入
 * @Author MyPC
 * @Date 2020/10/26
 * @Version 1.0
 */
public class ConstructorInjectTest {
    private Student student;
    private Baby baby;
    private int age;
    private String name;
    public ConstructorInjectTest(Student student, Baby baby){
        this.student=student;
        this.baby=baby;
    }
    public ConstructorInjectTest(int age,String name){
        this.age=age;
        this.name=name;
    }
    public static void main(String[] args) {
        //从类路径下根据文件名获取文件
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("constructor.xml");
        ConstructorInjectTest hello = (ConstructorInjectTest) applicationContext.getBean("hello");
        System.out.println(hello);
        System.out.println(hello.baby.age);
        System.out.println(hello.student.name);

    }

}
class Student{
    String name="小林";
}

class Baby{
    int age=2;
}
